<!-- stories/templates/stories/admin_review.html -->
{% extends 'stories/base.html' %}
{% load static %}
{% load story_extras %}

{% block title %}管理员审核 - AI故事生成网站{% endblock %}

{% block content %}
<div class="container">
    <div class="page-header">
        <h1>管理员审核中心</h1>
        <div class="page-actions">
            <a href="{% url 'stories:admin_dashboard' %}" class="btn btn-secondary">数据统计</a>
        </div>
    </div>

    <!-- 手动词汇查询表单 -->
    <div class="manual-search-form">
        <h2>手动词汇查询</h2>
        <form method="get" class="search-form">
            <div class="form-group">
                <input type="text" name="search_query" value="{{ search_query }}" placeholder="请输入要查询的词汇" class="form-control">
                <button type="submit" class="btn btn-primary">查询</button>
                {% if search_query %}
                    <a href="{% url 'stories:admin_review' %}" class="btn btn-secondary">清除</a>
                {% endif %}
            </div>
        </form>
    </div>

    {% if search_query %}
        <div class="search-results-section">
            <h2>包含"{{ search_query }}"的查询结果</h2>
            {% if search_results %}
                <div class="admin-review-list">
                    {% for story in search_results %}
                        <div class="review-item">
                            <div class="review-item-header">
                                <h3>
                                    <a href="{% url 'stories:review_story' story.id %}?search_query={{ search_query }}">{{ story.title }}</a>
                                    {% if story.status == 'pending' %}
                                        <span class="status-pending">(待审核)</span>
                                    {% elif story.status == 'published' %}
                                        <span class="status-published">(已发布)</span>
                                    {% elif story.status == 'draft' %}
                                        <span class="status-draft">(草稿)</span>
                                    {% elif story.status == 'rejected' %}
                                        <span class="status-rejected">(已驳回)</span>
                                    {% endif %}
                                </h3>
                                <span class="author">作者: {{ story.author.username }}</span>
                            </div>
                            <div class="review-item-meta">
                                <span class="category">{{ story.category.name }}</span>
                                <span class="date">提交时间: {{ story.created_at|date:"Y-m-d H:i" }}</span>
                            </div>
                            <div class="review-item-content">
                                <!-- 在内容中高亮显示查询词 -->
                                {% if search_query %}
                                    {{ story.content|highlight_word:search_query|linebreaks }}
                                {% else %}
                                    <p class="review-item-excerpt">{{ story.content|truncatewords:30 }}</p>
                                {% endif %}
                            </div>
                            <div class="review-item-actions">
                                <a href="{% url 'stories:review_story' story.id %}?search_query={{ search_query }}" class="btn btn-primary">审核</a>
                            </div>
                        </div>
                    {% endfor %}
                </div>
            {% else %}
                <div class="no-search-results">
                    <p>未找到包含"{{ search_query }}"的故事</p>
                </div>
            {% endif %}
        </div>
    {% else %}
        {% if pending_stories %}
            <div class="admin-review-list">
                <h2>待审核故事 ({{ pending_stories.count }})</h2>
                {% for story in pending_stories %}
                    <div class="review-item">
                        <div class="review-item-header">
                            <h3><a href="{% url 'stories:review_story' story.id %}">{{ story.title }}</a></h3>
                            <span class="author">作者: {{ story.author.username }}</span>
                        </div>
                        <div class="review-item-meta">
                            <span class="category">{{ story.category.name }}</span>
                            <span class="date">提交时间: {{ story.created_at|date:"Y-m-d H:i" }}</span>
                        </div>
                        <p class="review-item-excerpt">{{ story.content|truncatewords:30 }}</p>
                        <div class="review-item-actions">
                            <a href="{% url 'stories:review_story' story.id %}" class="btn btn-primary">审核</a>
                        </div>
                    </div>
                {% endfor %}
            </div>
        {% else %}
            <div class="no-pending-stories">
                <p>暂无待审核的故事</p>
            </div>
        {% endif %}
    {% endif %}
</div>
{% endblock %}